package servlet;

import bean.Result;
import biz.BizException;
import biz.userBiz;
import dao.QuerylistDao;
import utils.Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/setdafault.s")
public class setdafaultServlet extends HttpServlet {

    userBiz biz=new userBiz();
    QuerylistDao dao=new QuerylistDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final HttpSession session = req.getSession();
        final Integer userid = (Integer) session.getAttribute("userid");
        final String site = req.getParameter("site");
        final String name = req.getParameter("name");
        final String telphone = req.getParameter("telphone");
        Map<String,Object> map=new HashMap<>();
        Result result;
        try{
            map=dao.queryaid(site,name,telphone);
            final Integer aid = (Integer) map.get("id");
            biz.setdafault(aid,userid);
            result =new Result(1,"设置成功",null);
        } catch (BizException e) {
            result =new Result(0,e.getMessage(),null);
        }
        Util.WriteJson(result,resp);
    }
}
